IF EXISTS (SELECT * FROM sysobjects WHERE name = 'SaveMachineSrvrInstncMachine' AND type = 'P')
     DROP PROCEDURE dbo.SaveMachineSrvrInstncMachine
GO

CREATE PROCEDURE dbo.SaveMachineSrvrInstncMachine
     @SrvrInstncId                int,
     @PackageExecutionId          bigint,
     @ComputerNamePhysicalNetBIOS varchar(128) = NULL,
     @MachineName                 varchar(128) = NULL,
     @FQMachineName               varchar(255) = NULL,
     @PhysicalCPUCount            int          = NULL,
     @PhysicalCPUCoreCount        int          = NULL,
     @LogicalCPUCoreCount         int          = NULL,
     @MaxCPUSpeedMHz              INT          = NULL,
     @OSVersion                   VARCHAR(30)  = NULL,
     @OSLevel                     varchar(30)  = NULL,
     @OSArchitecture              varchar(10)  = NULL,
     @OSEdition                   varchar(128) = NULL,
     @TotalMachineMemoryMB        int          = NULL
AS
/*
 *
 * SaveMachineSrvrInstncMachine
 *
 * Purpose:      To provide a single interface to both the
 *               dbo.SaveMachine and dbo.SaveSrvrInstncMachine
 *               sprocs in the same call, this is useful for the SSIS data flow
 *               where it would be tricky to get the server machine id and pass
 *               it on to a later call.
 *
 * Inputs:       
 *
 * Assumes:      
 *
 * Effects:      
 *
 * Returns:      
 *
 * Note(s):      
 *
 * Author(s):    NOVA Concepts Ltd.
 *
 * Change Log:   Initial Release, 09/29/2011, 1.00.0000
 *
 */
BEGIN
     SET NOCOUNT ON
     SET XACT_ABORT ON

     DECLARE @MachineId int
     
     -- Handle the SrvrMachine First
     EXEC dbo.SaveMachine
               @PackageExecutionId          = @PackageExecutionId,
               @ComputerNamePhysicalNetBIOS = @ComputerNamePhysicalNetBIOS,
               @MachineName                 = @MachineName,
               @FQMachineName               = @FQMachineName,
               @PhysicalCPUCount            = @PhysicalCPUCount,
               @PhysicalCPUCoreCount        = @PhysicalCPUCoreCount,
               @LogicalCPUCoreCount         = @LogicalCPUCoreCount,
               @MaxCPUSpeedMHz              = @MaxCPUSpeedMHz,
               @OSVersion                   = @OSVersion,
               @OSLevel                     = @OSLevel,
               @OSArchitecture              = @OSArchitecture,
               @OSEdition                   = @OSEdition,
               @TotalMachineMemoryMB        = @TotalMachineMemoryMB,
               @MachineId                   = @MachineId OUTPUT

     IF ( @MachineId IS NOT NULL )
     BEGIN
          EXEC dbo.SaveSrvrInstncMachine
               @SrvrInstncId       = @SrvrInstncId,
               @MachineId          = @MachineId,
               @PackageExecutionId = @PackageExecutionId 
     END
     ELSE
     BEGIN
          PRINT 'Machine Id not available.'
     END
END
GO

EXEC sp_addextendedproperty @name = N'MS_Description', @value = 'This stored procedure does no real work itself, it provides a method to write server machine and server instance machine record, it calls the underlying sprocs SaveSrvrMachine and SaveSrvrInstncMachine in that order.', @level0type = N'Schema', @level0name = dbo, @level1type = N'PROCEDURE', @level1name = SaveMachineSrvrInstncMachine;
GO
